<?php

namespace common\repositories\myhtsq;

use common\repositories\BaseRepository;
use common\entities\myhtsq\ContractSuppliersPaymentEntity;
use yii\base\Exception;

class ContractSuppliersPaymentRepository extends BaseRepository
{

    /**
     * 批量写入
     * @param array $paymentList
     *
     * @return bool|int|string
     */
    public static function addPaymentBatch($paymentList = [])
    {
        if (empty($paymentList)) {
            return false;
        }

        try {
            $attributes = array_keys($paymentList[0]);
            $result = ContractSuppliersPaymentEntity::getDb()->createCommand()->batchInsert(ContractSuppliersPaymentEntity::tableName(), $attributes, $paymentList)->execute();

            return $result;
        } catch (Exception $e) {
            //return self::setAndReturn(ErrorCode::ERR_INVOICE_FORM_SAVE_FAIL, $ex->getMessage());
            return $e->getMessage();
        }
    }

    /**
     * 根据合同id获取支付列表
     * @param string $contract_id
     *
     * @return array|\yii\db\ActiveRecord[]
     */
    public static function getPaymentListByContractid($contract_id = '')
    {
        if (empty($contract_id)) {
            return [];
        }

        return ContractSuppliersPaymentEntity::find()->where(['contract_id' => $contract_id])->asArray()->all();
    }
}